<?php
require_once '../libs/app.config.php';
session_start();
if($_SESSION['LoginId'] == false){
	header("Location:login.php");
}

//show
if($_POST['action']=='show'){
	$goods_id = $_POST['id'];
	$sql = sprintf('select is_show from index_images where id=%d',$id);
	$query = $tpm->query($sql);
	if($tpm->num_rows($query)){
		$row = $tpm->fetch_array($query);
		if($row['is_show']){
			$is_show = 0;$r = array('ret'=>'ok','status'=>'no');
		}else{
			$is_show = 1;$r = array('ret'=>'ok','status'=>'yes');
		}
		$a = array('is_show'=>$is_show);
		$w = sprintf('id=%d',$id);
		$tpm->update('index_images',$a,$w);
		echo json_encode($r);
	}
	exit();

}

	ini_set ('memory_limit','128M');

	$upload = new UPImages2($annexFolder,$smallFolder,"","");
	$sql="select * from index_images order by id desc";
	$query=$tpm->query($sql);
	while($row=$tpm->fetch_array($query))
	{
		$index_image[]=$row;
	}

	if($_POST['submit']){
		$file=$_FILES;
		foreach ($file['fileDoc']['name'] as $k=>$v){
			$_FILES['fileDoc']['name']=$file['fileDoc']['name'][$k];
			$_FILES['fileDoc']['type']=$file['fileDoc']['type'][$k];
			$_FILES['fileDoc']['tmp_name']=$file['fileDoc']['tmp_name'][$k];
			$_FILES['fileDoc']['error']=$file['fileDoc']['error'][$k];
			$_FILES['fileDoc']['size']=$file['fileDoc']['size'][$k];
			$upload->maxWidth=500000000;
			$upload->maxHeight=500000000;
			$img=$upload->upLoad("fileDoc");
			$img_small=$upload->smallImg($img,"_small","300","300",true);

	        $sql="insert into index_images (`id`,`intro`,`images_url`,`images_link`) values(NULL,'".$_POST['intro'][$k]."','".$img."','".$_POST['images_link'][$k]."')";
			$query=$tpm->query($sql);
			if($query>0)
			{echo "<script>alert('添加成功');history.back();</script>";}

		}
	}
	//单项删除
	if($_POST['delid'])
	{
	   $sql="select * from index_images where id='".$_POST['delid']."'";
		$query=$tpm->query($sql);
		$row=$tpm->fetch_array($query);
		$path="../public/images_hot/ori/".$row['images_url'];
		if(file_exists($path))
		{@unlink($path);
		clearstatcache();}

		$sqls="delete from index_images where id='".$_POST['delid']."'";
		$querys=$tpm->query($sqls);

	}
require_once(INCLUDE_PATH.'template.inc.php');  //模板类及对象$tpl的加载
	$tpl->assign("index_image",$index_image);
	$tpl->display("index_images.html");
?>